const app = getApp()

import {
  getOrderDetailRequest
} from '../../api/user'


Page({

  /**
   * 页面的初始数据
   */
  data: {
    userName: "",           // 联系人
    userPhone: "",          // 联系电话
    useTime: "",            // 有效期
    creatTime: "",          // 创建时间
    payTime: "",            // 付款时间
    shopName: "",           // 店铺名称
    shopPhone: "",          // 商家电话
    shopAddress: "",        // 商家地址
    goodsId: '',
    qrcode: '',
    state:1,
    loading:false
  },

  onLoad: function (options) {
    var data = options.id;
    console.log('订单详情数据')
    console.log(data)
    this.setData({
      goodsId: data,
    })
    console.log(this.data.goodsId)

    wx.setNavigationBarTitle({
      title: '订单详情',
    })
    this.getData()
    var that = this
    setTimeout(function() {
      that.setData({
        loading:true
      })
    }, 300);
  },

  /** 数据匹配 */
  getData: function () {

    let that = this
    let params = {
      id: this.data.goodsId,
    };
    getOrderDetailRequest(params).then((res) => {
      console.log('>>>>>>>>  请求的数据')
      console.log(res)

      let result = res.result
      console.log('>>>')
      console.log(result)
      var base64Image = result.qrcode // 后台返回的base64数据
      var imgData = base64Image.replace(/[\r\n]/g, '') // 将回车换行换为空字符''

      that.setData({ 
        userName: result.nickName,           // 联系人
        userPhone: result.mobile,          // 联系电话
        useTime: result.invalidTime == undefined ? "" : result.invalidTime,            // 有效期
        creatTime: result.createTime,          // 创建时间
        payTime: result.payTime,            // 付款时间
        shopName: result.merchantsInfo.name,           // 店铺名称
        shopPhone: result.merchantsInfo.mobile,          // 商家电话
        shopAddress: result.merchantsInfo.address,        // 商家地址
        qrcode: imgData,
        state:result.state
      });
    }).catch((res) => {
      console.log('getOrderDetailRequest请求失败')
      console.log(res)
      tt.showToast({
        title: res.data.msg,
        icon: 'none',
        duration: 2000
      })
    })
  },
})
